
//
// 120615 - (AH) - Created.
//

package org.soekrat.environment;

import org.soekrat.AttributeObject;

/**
 * <p>
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class Orb extends AttributeObject 
{
  /**
   * <p>
   *   The name on the attribute for {@code this} and 
   *   {@link ConversationEvent}s for what has for what has been painted. 
   * </p>
   */
  public static final String PAINT="paint";
  
  private boolean m_log=true;
  
  /**
   * <p>
   *   Tells if log messages are logged.
   * </p>
   * @return {@code true} if are, {@code false} if are not.
   */
  public final boolean log(){ return m_log; }
  
  /**
   * <p>
   *   Sets if log messages are logged.
   * </p>
   * @param log {@code true} if are to be, {@code false} if are not to be.
   */
  public final void log(boolean log){ m_log=log; }
  
  /**
   * <p>
   *   Logs.
   * </p>
   * <p>
   *   Messages will only be logged if
   *   {@link #log()}{@code ==true}.
   * </p>
   * @param source Source class (for static methods) or object logging. May be
   *               {@code null}.
   * @param method Name of method logging. May be {@code null}.
   * @param msg    Log message. Should not be {@code null} of course but is
   *               allowed to be.
   * @return {@code this}.
   */
  public Orb log(Object source, String method, String msg)
  {
    if (!log()) return this;
    
    StringBuilder sb=new StringBuilder(">> ");
    
    String src=null;
    if (source!=null)
    {
      if (source instanceof Class<?>) src=((Class<?>)source).getSimpleName();
      else                            src=source.getClass().getSimpleName();
    }
    
    if (src!=null) sb.append(src).append(" : ");
    
    if (method!=null) sb.append(method).append(" : ");
    
    if (msg==null) sb.append("no message!");
    else           sb.append(msg);
    
    String compiled=sb.toString();
    
    System.out.println();
    System.out.println(compiled);
    System.out.println();
    
    return this;
  }
  
}
